package com.toman.ui.menu;

import android.app.Activity;
import android.os.Bundle;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.toman.Enum.BaseEnum;
import com.toman.Enum.PermEnum;
import com.toman.JavaBean.DeviceHouseDayPlanEntity;
import com.toman.JavaBean.DeviceHouseMonthDayPlanEntity;
import com.toman.JavaBean.DeviceHouseMonthPlanEntity;
import com.toman.JavaBean.MessageDataBean;
import com.toman.JavaBean.SysUserEntity;
import com.toman.Util.IntentUtils;
import com.toman.Util.PermissonUtils;
import com.toman.Util.SPUtils;
import com.toman.Util.StringUtils;
import com.toman.ui.work.base.DepartmentInfActivity;
import com.toman.ui.work.base.ShiftEmptyActivity;
import com.toman.ui.work.base.UserInfActivity;
import com.toman.ui.work.base.WorkcalendarActivity;
import com.toman.ui.work.choose.ChooseBeltlineEmptyActivity;
import com.toman.ui.work.choose.ChooseCompanyListEmptyActivity;
import com.toman.ui.work.choose.ChooseDepartmentListEmptyActivity;
import com.toman.ui.work.choose.ChooseDeviceEmptyActivity;
import com.toman.ui.work.choose.ChooseDeviceModeEmptyActivity;
import com.toman.ui.work.choose.ChooseDeviceTypeListEmptyActivity;
import com.toman.ui.work.choose.ChooseHardwaveListEmptyActivity;
import com.toman.ui.work.choose.ChooseProblemItemListEmptyActivity;
import com.toman.ui.work.choose.ChooseRemindListEmptyActivity;
import com.toman.ui.work.choose.ChooseRoleListEmptyActivity;
import com.toman.ui.work.device.CompleteEquipmentActivity;
import com.toman.ui.work.device.DeviceRepairActivity;
import com.toman.ui.work.device.PreMaintenanceActivity;
import com.toman.ui.work.device.PreviewHotActivity;
import com.toman.ui.work.device.PreviewHotConfigActivity;
import com.toman.ui.work.device.TallyActivity;
import com.toman.ui.work.management.BeltlineInspectActivity;
import com.toman.ui.work.management.ProblemFeedbackActivity;
import com.toman.ui.work.workplan.WorkshopDayPlanActivity;
import com.toman.ui.work.workplan.WorkshopMonthPlanActivity;
import com.toman.ui.work.workplan.WorkshopSubmitActivity;
import com.toman.ui.work.workshop.CenterTableActivity;
import com.toman.ui.work.workshop.ChangeWheelActivity;
import com.toman.ui.work.workshop.DispatchingActivity;
import com.toman.ui.work.workshop.FirstInspectionActivity;
import com.toman.ui.work.workshop.GetActivity;
import com.toman.ui.work.workshop.InspectionReportActivity;
import com.toman.ui.work.workshop.NoPlanSubmitActivity;
import com.toman.ui.work.workshop.PlanActivity;
import com.toman.ui.work.workshop.SubmitActivity;

/**
 * Created by 邹苏隆 on 2019/1/25.
 * description：
 */
public class MenuJump {
    public static void go(Activity activity,String name){
        BaseEnum valueByName = BaseEnum.getValueByName(name);
        if (valueByName==null){
            return;
        }
        Bundle bundle = new Bundle();
        final String departmentId = (String) SPUtils.get(activity, "departmentId", "");
        final String companyId = (String) SPUtils.get(activity, "cpy_id", "");

        final String userId = (String) SPUtils.get(activity, "userid", "");
        switch (valueByName) {
            case COMPANY:
                bundle.putString("msg", name);
                IntentUtils.startActivity(activity, ChooseCompanyListEmptyActivity.class, bundle);
                break;
//                    部门信息
            case DEPARTMENT:
                if (PermissonUtils.contains(activity, BaseEnum.COMPANY.has(PermEnum.LOOK))) {
                    bundle.putString("msg", name);
                    IntentUtils.startActivity(activity, ChooseCompanyListEmptyActivity.class, bundle);
                } else if (PermissonUtils.contains(activity, BaseEnum.DEPARTMENT.has(PermEnum.LOOK))) {
                    bundle.putString("msg", name);
                    IntentUtils.startActivity(activity, ChooseDepartmentListEmptyActivity.class, bundle);
                } else {
                    bundle.putString("id", departmentId);
                    IntentUtils.startActivity(activity, DepartmentInfActivity.class, bundle);
                }

                break;
//                    人员信息
            case USER:
                if (PermissonUtils.contains(activity, BaseEnum.COMPANY.has(PermEnum.LOOK))) {
                    bundle.putString("msg", name);
                    IntentUtils.startActivity(activity, ChooseCompanyListEmptyActivity.class, bundle);
                } else if (PermissonUtils.contains(activity, BaseEnum.DEPARTMENT.has(PermEnum.LOOK))) {
                    bundle.putString("msg", name);
                    IntentUtils.startActivity(activity, ChooseDepartmentListEmptyActivity.class, bundle);
                } else {
                    bundle = new Bundle();
                    bundle.putString("id", userId);
                    IntentUtils.startActivity(activity, UserInfActivity.class, bundle);
                }
                break;
//                    固件信息
            case HARDWAVE:
                bundle.putString("msg", name);
                IntentUtils.startActivity(activity, ChooseHardwaveListEmptyActivity.class, bundle);
                break;
//                    产线信息
            case BELT:
                if (PermissonUtils.contains(activity, BaseEnum.COMPANY.has(PermEnum.LOOK))) {
                    bundle.putString("msg", name);
                    IntentUtils.startActivity(activity, ChooseCompanyListEmptyActivity.class, bundle);
                } else if (PermissonUtils.contains(activity, BaseEnum.DEPARTMENT.has(PermEnum.LOOK))) {
                    bundle.putString("msg", name);
                    IntentUtils.startActivity(activity, ChooseDepartmentListEmptyActivity.class, bundle);
                } else {
                    bundle = new Bundle();
                    bundle.putString("id", departmentId);
                    bundle.putString("msg", name);
                    IntentUtils.startActivity(activity, ChooseBeltlineEmptyActivity.class, bundle);
                }

                break;
//                    终端信息
            case TERMINAL:
                if (PermissonUtils.contains(activity, BaseEnum.COMPANY.has(PermEnum.LOOK))) {
                    bundle = new Bundle();
                    bundle.putString("msg", name);
                    IntentUtils.startActivity(activity, ChooseCompanyListEmptyActivity.class, bundle);
                } else {
                    bundle = new Bundle();
                    bundle.putString("id", departmentId);
                    bundle.putString("msg", name);
                    IntentUtils.startActivity(activity, ChooseHardwaveListEmptyActivity.class, bundle);
                }
                break;
//                    班次信息
            case SHIFT:
//                if (PermissonUtils.contains(activity, BaseEnum.COMPANY.has(PermEnum.LOOK))) {
//                    bundle = new Bundle();
//                    bundle.putString("msg", name);
//                    IntentUtils.startActivity(activity, ChooseCompanyListEmptyActivity.class, bundle);
//                } else if (PermissonUtils.contains(activity, BaseEnum.DEPARTMENT.has(PermEnum.LOOK))) {
//                    bundle = new Bundle();
//                    bundle.putString("msg", name);
//                    IntentUtils.startActivity(activity, ChooseDepartmentListEmptyActivity.class, bundle);
//                } else {
                    bundle = new Bundle();
                    bundle.putString("id", departmentId);
                    bundle.putString("msg", name);
                    IntentUtils.startActivity(activity, ShiftEmptyActivity.class, bundle);
//                }
                break;
//                    工作日历
            case WORKCALENDAR:
                if (PermissonUtils.contains(activity, BaseEnum.COMPANY.has(PermEnum.LOOK))) {
                    bundle = new Bundle();
                    bundle.putString("msg", name);
                    IntentUtils.startActivity(activity, ChooseCompanyListEmptyActivity.class, bundle);
                } else if (PermissonUtils.contains(activity, BaseEnum.DEPARTMENT.has(PermEnum.LOOK))) {
                    bundle = new Bundle();
                    bundle.putString("msg", name);
                    IntentUtils.startActivity(activity, ChooseDepartmentListEmptyActivity.class, bundle);
                } else {
                    bundle = new Bundle();
                    bundle.putString("id", departmentId);
                    bundle.putString("msg", name);
                    IntentUtils.startActivity(activity, WorkcalendarActivity.class, bundle);
                }

                break;
//                    提醒作业
            case REMIND:
                bundle = new Bundle();
                bundle.putString("msg", name);
                IntentUtils.startActivity(activity, ChooseRemindListEmptyActivity.class, bundle);
//                        IntentUtils.startActivity(activity, WorkcalendarActivity.class,bundle);

                break;
//                    角色管理 修改为角色信息
            case ROLE:
                bundle = new Bundle();
                bundle.putString("msg", name);
                IntentUtils.startActivity(activity, ChooseRoleListEmptyActivity.class, bundle);
//                        IntentUtils.startActivity(activity, WorkcalendarActivity.class,bundle);

                break;
//                    故障项目
            case PROBLEMITEM:
                bundle = new Bundle();
                bundle.putString("msg", name);
                IntentUtils.startActivity(activity, ChooseProblemItemListEmptyActivity.class, bundle);
//                        IntentUtils.startActivity(activity, WorkcalendarActivity.class,bundle);
                break;
//                    设备类别
            case DEVICEMODE:
                bundle = new Bundle();
                bundle.putString("msg", name);
                IntentUtils.startActivity(activity, ChooseDeviceTypeListEmptyActivity.class, bundle);
//                        IntentUtils.startActivity(activity, WorkcalendarActivity.class,bundle);
                break;
//                    设备型号
            case DEVICETYPE:
                bundle = new Bundle();
                bundle.putString("msg", name);
                IntentUtils.startActivity(activity, ChooseDeviceModeEmptyActivity.class, bundle);
//                        IntentUtils.startActivity(activity, WorkcalendarActivity.class,bundle);
                break;
//                    设备信息
            case DEVICEINF:
                bundle = new Bundle();
                bundle.putString("msg", name);
                IntentUtils.startActivity(activity, ChooseDeviceEmptyActivity.class, bundle);
//                        IntentUtils.startActivity(activity, WorkcalendarActivity.class,bundle);
                break;

            case PREVIEWHOTCONFIG:
                bundle = new Bundle();
                bundle.putString("msg", name);
                IntentUtils.startActivity(activity, PreviewHotConfigActivity.class, bundle);
                break;
            
            
//                    问题反馈
            case FEEDBACK:
                 bundle = new Bundle();
                bundle.putString("msg", valueByName.name);
                IntentUtils.startActivity(activity, ProblemFeedbackActivity.class, bundle);
                break;
//                    产线巡检
            case BELTLINEINSPECT:
                bundle = new Bundle();
                if (PermissonUtils.contains(activity, BaseEnum.COMPANY.has(PermEnum.LOOK))) {
                    bundle = new Bundle();
                    bundle.putString("msg", valueByName.name);
                    IntentUtils.startActivity(activity, ChooseCompanyListEmptyActivity.class, bundle);
                } else {
                    bundle = new Bundle();
                    bundle.putString("msg", valueByName.name);
                    IntentUtils.startActivity(activity, BeltlineInspectActivity.class, bundle);
                }
                break;

            case TALLY:
                bundle.putString("msg", valueByName.name);
                IntentUtils.startActivity(activity, TallyActivity.class, bundle);
                break;
//                    预维护
            case PRE:
                bundle = new Bundle();
                bundle.putString("msg", valueByName.name);
                IntentUtils.startActivity(activity, PreMaintenanceActivity.class, bundle);
                break;
//                    完好检查
            case CHECK:
                bundle = new Bundle();
                bundle.putString("msg", valueByName.name);
                IntentUtils.startActivity(activity, CompleteEquipmentActivity.class, bundle);
                break;

//                    报修维修
            case REPAIR:
                bundle = new Bundle();
                bundle.putString("msg", valueByName.name);
                IntentUtils.startActivity(activity, DeviceRepairActivity.class, bundle);
                break;

            case PREVIEWHOT:

                bundle = new Bundle();
                IntentUtils.startActivity(activity, PreviewHotActivity.class, bundle);

                break;

            //                    车间计划
            case PLAN:
                bundle.putString("msg", valueByName.name);
                IntentUtils.startActivity(activity, PlanActivity.class, bundle);
                break;
//                    派工信息
            case DISPATCHING:
                bundle = new Bundle();
                bundle.putString("msg", valueByName.name);
                IntentUtils.startActivity(activity, DispatchingActivity.class, bundle);
                break;
//                    报工信息
            case SUBMIT:
                bundle = new Bundle();
                bundle.putString("msg", valueByName.name);
                IntentUtils.startActivity(activity, SubmitActivity.class, bundle);
                break;

//                    领工信息
            case GET:
                bundle = new Bundle();
                bundle.putString("msg", valueByName.name);
                IntentUtils.startActivity(activity, GetActivity.class, bundle);
                break;

            case FIRSTINSPECTION:
                bundle = new Bundle();
                bundle.putString("msg", valueByName.name);
                IntentUtils.startActivity(activity, FirstInspectionActivity.class, bundle);
                break;
            case INSPECTIONREPORT:
                bundle = new Bundle();
                bundle.putString("msg", valueByName.name);
                IntentUtils.startActivity(activity, InspectionReportActivity.class, bundle);
                break;
            case CENTERTABLE:
                bundle = new Bundle();
                bundle.putString("msg", valueByName.name);
                IntentUtils.startActivity(activity, CenterTableActivity.class, bundle);
                break;
            case CHANGEWHEEL:
                bundle = new Bundle();
                bundle.putString("msg", valueByName.name);
                IntentUtils.startActivity(activity, ChangeWheelActivity.class, bundle);
                break;
            case NOPLANSUBMIT:
                bundle = new Bundle();
                bundle.putString("msg", valueByName.name);
                IntentUtils.startActivity(activity, NoPlanSubmitActivity.class, bundle);
                break;

            case WORKSHOPDAYPLAN:
                
                if (PermissonUtils.contains(activity, BaseEnum.WORKSHOPDAYPLAN.has(PermEnum.ADD))) {
                    bundle = new Bundle();
                    bundle.putString("msg", valueByName.name);
                    bundle.putString("id", companyId);

                    IntentUtils.startActivity(activity, ChooseDepartmentListEmptyActivity.class, bundle);
                } else {
                    bundle = new Bundle();
                    bundle.putString("msg", valueByName.name);
                    IntentUtils.startActivity(activity, WorkshopDayPlanActivity.class, bundle);
                }
                break;
            case WORKSHOPMONTHPLAN:
                if (PermissonUtils.contains(activity, BaseEnum.WORKSHOPMONTHPLAN.has(PermEnum.ADD))) {
                    bundle = new Bundle();
                    bundle.putString("msg", valueByName.name);
                    bundle.putString("id", companyId);

                    IntentUtils.startActivity(activity, ChooseDepartmentListEmptyActivity.class, bundle);
                } else {
                    bundle = new Bundle();
                    bundle.putString("msg", valueByName.name);
                    IntentUtils.startActivity(activity, WorkshopMonthPlanActivity.class, bundle);
                }
                break;

            case WORKSHOPSUBMIT:

                bundle = new Bundle();
                bundle.putString("msg", valueByName.name);
                IntentUtils.startActivity(activity, WorkshopSubmitActivity.class, bundle);
                break;

        }
    };




    public static void  dealMsg(Activity activity,MessageDataBean bean) {
        Bundle bundle = new Bundle();
        bundle.putString("status", bean.getOperateType());
        bundle.putString("etSearch",bean.getRecordId()+"");
        if (StringUtils.isNotEmpty(bean.getTabIndex())){
            bundle.putString("status", bean.getTabIndex());
        }
        switch (bean.getType()) {
            case "1":
                IntentUtils.startActivity(activity, TallyActivity.class, bundle);
                break;
            case "2":
                IntentUtils.startActivity(activity, CompleteEquipmentActivity.class, bundle);
                break;
            case "3":
                IntentUtils.startActivity(activity, PreMaintenanceActivity.class, bundle);
                break;
            case "4":
                IntentUtils.startActivity(activity, DeviceRepairActivity.class, bundle);
                break;
            case "6":
                IntentUtils.startActivity(activity, PlanActivity.class, bundle);
                break;
            case "7":
                IntentUtils.startActivity(activity, DispatchingActivity.class, bundle);
                break;
            case "8":
                IntentUtils.startActivity(activity, GetActivity.class, bundle);
                break;
            case "9":
bundle.putString("isfirstReport",bean.getExtra());
                IntentUtils.startActivity(activity, SubmitActivity.class, bundle);
                break;
            case "12":
                IntentUtils.startActivity(activity, ProblemFeedbackActivity.class, bundle);
                break;
            case "13":
                IntentUtils.startActivity(activity, ChooseRemindListEmptyActivity.class, bundle);
                break;
            case "14":
                IntentUtils.startActivity(activity, NoPlanSubmitActivity.class, bundle);
                break;
            case "15":
                JSONObject jsonObject= (JSONObject) bean.getExtraMap().get("entity");
                bundle.putSerializable("entity", (DeviceHouseMonthPlanEntity)JSONObject.parseObject(jsonObject.toJSONString(),DeviceHouseMonthPlanEntity.class));
                IntentUtils.startActivity(activity, WorkshopMonthPlanActivity.class, bundle);
                break;
            case "16":
                 jsonObject= (JSONObject) bean.getExtraMap().get("entity");
                bundle.putSerializable("entity", (DeviceHouseDayPlanEntity)JSONObject.parseObject(jsonObject.toJSONString(),DeviceHouseDayPlanEntity.class));
                IntentUtils.startActivity(activity, WorkshopDayPlanActivity.class, bundle);
                break;
            case "17":
                IntentUtils.startActivity(activity, WorkshopSubmitActivity.class, bundle);
                break;
            case "18":
                IntentUtils.startActivity(activity, PreviewHotActivity.class, bundle);
                break;

            case "19":
                IntentUtils.startActivity(activity, CenterTableActivity.class, bundle);
                break;

        }
    }
}
